local bmp = require "bmp"
local lv = require "lv_img"
--lvgl中代表16位色
local color = 16
--lvgl的宏:LV_IMG_CF_TRUE_COLOR,根据实际去修改
local cf = 4
--[[
    path_t:文件列表
    save_path:保存文件的地址


    错误类型:
const char BMP_ERR_STR[BMP_ERR_MAX][64] = 
{
	"BMP_SUCCESS",
	"BMP_ERR_HEAD", //bmp头出问题
	"BMP_ERR_COMPRESS",//bmp是压缩过的
	"BMP_ERR_CLRUSED",//
	"BMP_ERR_BITCOUNT",//不是32位或者24位
};


--]]
function bmp_saveLv(path_t,save_path,rev,tranColor,replaceColor)
    local rgb_buf,w,h,fp,read_buf,err
    local filename
    local rev = rev or true
    replaceColor = tonumber(replaceColor) or 0
    tranColor    = tonumber(tranColor) or 0
    --轮询rgb图片的地址,并且转换成lvImg的数据格式
    for k,v in ipairs(path_t) do
        fp = io.open(v.path,"rb")
        read_buf = fp:read("*a")
        fp:close()
        err,w,h,rgb_buf = bmp.bmp_to_rgb(read_buf,rev,tranColor,replaceColor)
        if err == 0 then
            filename = string.format("%s%s.lv",save_path,v.filename)
            fp = io.open(filename,"wb")
            --写入数据头
            fp:write(lv.getlvImg(color,cf,w,h))
            --保存rgb数据
            fp:write(rgb_buf)
            fp:close()
        else
            print(string.format("BMP_TO_RGB fail:%s,err code:%d",v.path,err))
        end
        
    end
end